#ifndef Scenic_Renderer_SimpleMediaFile_h
#define Scenic_Renderer_SimpleMediaFile_h

#ifdef DIRECTX

#include <windows.h>
#include <mmsystem.h>
#include <atlbase.h>
#include <stdio.h>

#include <d3dx9.h>
#include <d3d9.h>
#include <d3d9types.h>
#include <strmif.h>
#include <control.h>
#include <streams.h>
#include <Dvdmedia.h>

#endif

#include "Resource.h"
#include "common.h"

namespace Scenic
{
namespace Renderer
{
#ifdef DIRECTX
struct __declspec(uuid("{2983D02A-2F26-48d9-97E5-52278D4D36DA}")) CLSID_ImageRenderer;

class ImageRenderer : public CBaseVideoRenderer
{
	Image *image;
	JNIEnv *threadEnv;
	int isUpsideDown;
public:
    ImageRenderer(Image *image);
    ~ImageRenderer();
	
public:
    HRESULT CheckMediaType(const CMediaType *pmt);     // Format acceptable?
    HRESULT SetMediaType(const CMediaType *pmt);       // Video format notification
    HRESULT DoRenderSample(IMediaSample *pMediaSample); // New video sample

private:
	void detachThread();
};
#endif

class SimpleMediaFile : public Resource
{
	char *filename;
	Image *image;
#ifdef DIRECTX
	ImageRenderer *imageRenderer;
	
	CComPtr<IGraphBuilder> graphBuilder;
	CComPtr<IMediaControl> mediaControl;
	CComPtr<IMediaPosition> mediaPosition;
	CComPtr<IMediaEvent> mediaEvent;
	CComPtr<IBaseFilter> renderer;
#endif
public:
	SimpleMediaFile(const char *filename, Image *image);
	~SimpleMediaFile();
	
	void play();
	void pause();
	double getCurrentPosition();
	void setCurrentPosition(double position);
	double getLength();
	
	static SimpleMediaFile *get(int id);
private:
	bool initRenderer();
	void release();
};

}
}

#endif
